package org.lemon.db.store;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

/**
 * @since 2024-12-11 20:28
 */
public class LogManagerTest1 {
    @Test
    public void testLogManager() throws Exception{
        FileManager fm = FileManager.create("./target/file_test/",1024 * 4);
        LogManager logManager = new LogManager(fm,"logfile" + System.currentTimeMillis());
        int recNum = 100000;
        createRecords(logManager, 1, recNum);
        LogIterator logIterator = logManager.iterator();

        while (logIterator.hasNext()){
            byte[] records = logIterator.next();
            Assertions.assertEquals("record" + recNum, new String(records));
            recNum--;
        }
    }

    private void createRecords(LogManager logManager,int start , int end ){
        for(;start <= end; start++){
            String s  = "record" + start;
            logManager.append(s);
        }
    }
}
